package com.wsd.socket.step4;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.HashMap;

public class Response {
	Socket socket;
	private Integer status;
	private static HashMap<Integer, String> codeMap;
	public Response(Socket socket) {
		this.socket = socket;
		if(codeMap == null) {
			this.status = 200;
			codeMap = new HashMap<Integer, String>();
			codeMap.put(200, "OK");
		}
	}
	
	public void send(String msg) throws IOException {
		String resp = "HTTP/1.1 200 ok\n";
		resp += "\n";
		resp += msg;
		this.sendRaw(resp);
	}
	
	public void sendRaw(String msg) throws IOException {
		BufferedWriter bfWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
		System.out.println(msg);
		bfWriter.write(msg);
		bfWriter.flush();
		socket.close();
	}

}
